﻿using IcicleFramework.Components;
using IcicleFramework.Components.Health;
using IcicleFramework.Entities;

namespace ExampleGame.Components.Score
{
    public class PointsOnDeathComponent : PointsComponent
    {
        public PointsOnDeathComponent() : base() { }

        protected PointsOnDeathComponent(PointsOnDeathComponent old)
            : base(old) { }

        public override void Initialize()
        {
            IHealthComponent healthComponent = this.Parent.GetComponent<IHealthComponent>();

            if (healthComponent != null)
                healthComponent.OnHealthDepleted += OnHealthDepleted;
        }

        public virtual void OnHealthDepleted(IHealthComponent sender, IGameObject damageInitiator)
        {
            //Fire off our add points event!
            this.OnAddPoints(damageInitiator);
        }

        public override IBaseComponent DeepClone()
        {
            return new PointsOnDeathComponent(this);
        }
    }
}
